
import java.io.*;
import java.util.*;
import java.net.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import java.sql.Statement;

public class Login extends HttpServlet {

    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("text/html");
        
        PrintWriter out = response.getWriter();
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        ResultSet rs1 = null;
        String uid = request.getParameter("UserId");
        String pw = request.getParameter("Password");
        String name = new String("");
        String pw1 = new String("");

    
        try 
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "admin");
            stmt = con.createStatement();
            rs = stmt.executeQuery("SELECT * FROM pass_profile where user_id='" + uid + "'");
            while (rs.next()) 
            {
                name = rs.getString("user_id");
            }
 
            rs1 = stmt.executeQuery("SELECT password FROM pass_profile where user_id='" + uid + "'");
            while (rs1.next()) 
            {
                pw1 = rs1.getString("password");
            }
            if (uid.equals(name))
            {
                if(pw.equals(pw1))
                {
                    HttpSession log = request.getSession(true);           
                    log.setAttribute("l", uid);
                    System.out.println("1   " + uid);
                    response.sendRedirect("UserProfile.jsp");
                }
                else
                {
                    response.sendRedirect("LoginError.jsp");
                }
            } 
        else
        {
            response.sendRedirect("LoginError1.jsp");
        }
        
        rs.close();
        rs1.close();
        stmt.close();
    }
    catch(Exception e)
    {
        System.out.println(e);
    }
}
}